﻿@using Smartstore.Web.Models.Customers;

@model CustomerOrderListModel

@{
    Assets.AppendTitleParts(T("PageTitle.Account"));

    Layout = "_MyAccount";
    ViewBag.PageClassToken = "orders";
    ViewBag.PageTitle = T("Account.CustomerOrders").Value;
}

@if (Model.RecurringPayments.Count > 0)
{
    <div sm-if="Model.CancelRecurringPaymentErrors.Count > 0" class="alert alert-danger">
        @for (int i = 0; i < Model.CancelRecurringPaymentErrors.Count; i++)
        {
            <p>@Model.CancelRecurringPaymentErrors[i]</p>
        }
    </div>

    <form asp-action="Orders">
        <div class="recurring-payments mb-4">
            <fieldset class="content-group mb-0">
                <legend class="mb-0">
                    <span>@T("Account.CustomerOrders.RecurringOrders")</span>
                </legend>
            </fieldset>

            <div class="recurring-payments-box table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th class="border-0">
                                @T("Account.CustomerOrders.RecurringOrders.StartDate")
                            </th>
                            <th class="border-0">
                                @T("Account.CustomerOrders.RecurringOrders.CycleInfo")
                            </th>
                            <th class="border-0">
                                @T("Account.CustomerOrders.RecurringOrders.NextPayment")
                            </th>
                            <th class="text-center border-0">
                                @T("Account.CustomerOrders.RecurringOrders.TotalCycles")
                            </th>
                            <th class="text-center border-0">
                                @T("Account.CustomerOrders.RecurringOrders.CyclesRemaining")
                            </th>
                            <th class="border-0">
                                &nbsp;
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.RecurringPayments)
                        {
                            <tr>
                                <td title="@item.NextPayment.ToString()">@item.StartDate.ToString("d")</td>
                                <td>@item.CycleInfo</td>
                                <td title="@item.NextPayment.ToString()">@(item.NextPayment.HasValue ? ((DateTime)item.NextPayment).ToString("d") : string.Empty)</td>
                                <td class="text-center">@item.TotalCycles</td>
                                <td class="text-center">@item.CyclesRemaining</td>
                                <td>
                                    <div class="dropdown">
                                        <button type="button" class="btn btn-secondary btn-sm dropdown-toggle text-right" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                            ...
                                        </button>
                                        <div class="dropdown-menu @(WorkContext.WorkingLanguage.Rtl ? "dropdown-menu-right" : "dropdown-menu-left")">
                                            <a asp-action="Details" asp-controller="Order" asp-route-id="@item.InitialOrderId" class="dropdown-item" rel="nofollow">
                                                <i class="far fa-list-alt"></i>
                                                <span>@T("Account.CustomerOrders.RecurringOrders.ViewInitialOrder", item.InitialOrderId)</span>
                                            </a>
                                            <button sm-if="item.CanCancel" type="submit" name="cancelRecurringPayment@(item.Id)" value="cancelRecurringPayment@(item.Id)" class="dropdown-item btn btn-link">
                                                <i class="fa fa-times"></i>
                                                <span>@T("Account.CustomerOrders.RecurringOrders.Cancel")</span>
                                            </button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div sm-if="Model.RecurringPayments.TotalPages > 1" class="mt-1">
                    <pagination sm-list-items="Model.RecurringPayments" sm-query-param="recurringPaymentsPage" id="rp-paginator" />
                </div>
            </div>
        </div>
    </form>
}

@if (Model.Orders.Count == 0)
{
    <div class="alert alert-warning">
        @T("Account.CustomerOrders.NoOrders")
    </div>
    return;
}

<div class="card-deck card-cols-sm-1 order-list">
    @foreach (var order in Model.Orders)
    {
        <div class="card shadow-sm order-item">
            <div class="card-body">
                <h4 class="card-title mb-4">@T("Order.Order#"): @order.OrderNumber</h4>
                <dl class="row mb-0">
                    <dt class="col-sm-3 font-weight-400 text-muted">@T("Order.OrderStatus")</dt>
                    <dd class="col-sm-9">@order.OrderStatus</dd>
                    <dt class="col-sm-3 font-weight-400 text-muted">@T("Order.OrderDate")</dt>
                    <dd class="col-sm-9">@order.CreatedOn.ToNativeString()</dd>
                    <dt class="col-sm-3 font-weight-400 text-muted">@T("Order.OrderTotal")</dt>
                    <dd class="col-sm-9 price">@order.OrderTotal</dd>
                </dl>
            </div>

            <div class="card-footer d-flex p-0">
                <a asp-action="Details" asp-controller="Order" asp-route-id="@order.Id" class="btn btn-secondary btn-flat rounded-0" rel="nofollow">
                    <i class="far fa-list-alt"></i>
                    <span>@T("Order.OrderDetails")</span>
                </a>
                @if (order.IsReturnRequestAllowed)
                {
                    <a asp-action="ReturnRequest" asp-controller="ReturnRequest" asp-route-id="@order.Id" class="btn btn-secondary btn-flat rounded-0" rel="nofollow">
                        <i class="fa fa-reply"></i>
                        <span>@T("Account.CustomerOrders.ReturnItems")</span>
                    </a>
                }
            </div>
        </div>
    }
</div>

<div sm-if="Model.Orders.TotalPages > 1" class="mt-1">
    <pagination sm-list-items="Model.Orders" sm-query-param="page" id="paginator" />
</div>